home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / nonansi.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  24KB  |  736 lines

  1. /***********************************************************************/
  2. /* NONANSI.C -                                                         */
  3. /* This file contains all calls to non-ansi conforming routines.       */
  4. /***********************************************************************/
  5. /*
  6.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  7.  * Copyright (C) 1991-1995 Mark Hessling
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License as
  11.  * published by the Free Software Foundation; either version 2 of
  12.  * the License, or any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17.  * General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to:
  21.  *
  22.  *    The Free Software Foundation, Inc.
  23.  *    675 Mass Ave,
  24.  *    Cambridge, MA 02139 USA.
  25.  *
  26.  *
  27.  * If you make modifications to this software that you feel increases
  28.  * it usefulness for the rest of the community, please email the
  29.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  30.  * This software is going to be maintained and enhanced as deemed
  31.  * necessary by the community.
  32.  *
  33.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  34.  * 36 David Road                     Phone: +61 7 849 7731
  35.  * Holland Park                      Fax:   +61 7 875 5314
  36.  * QLD 4121
  37.  * Australia
  38.  */
  39.  
  40. /*
  41. $Id: nonansi.c 2.0 1995/01/26 16:31:28 MH Release MH $
  42. */
  43.  
  44. #include <stdio.h>
  45.  
  46. #include <errno.h>
  47.  
  48. #include "the.h"
  49. #include "proto.h"
  50.  
  51. #ifdef UNIX
  52. #include <pwd.h>
  53. #endif
  54.  
  55. /*#define DEBUG 1*/
  56.  
  57. #ifdef DOS
  58. #  include <dos.h>
  59. #  ifndef GO32
  60. #    include <direct.h>
  61. #  endif
  62. #endif
  63.  
  64. #ifdef OS2
  65. #  ifndef EMX
  66. #    include <direct.h>
  67. #  endif
  68. #  include <io.h>
  69. #  ifndef S_IFMT
  70. #    define S_IFMT 0xF000
  71. #  endif
  72. #endif
  73.  
  74. /***********************************************************************/
  75. #ifdef PROTO
  76. short file_readable(CHARTYPE *filename)
  77. #else
  78. short file_readable(filename)
  79. CHARTYPE *filename;
  80. #endif
  81. /***********************************************************************/
  82. {
  83. /*--------------------------- local data ------------------------------*/
  84. /*--------------------------- processing ------------------------------*/
  85. #ifdef TRACE
  86.  trace_function("nonansi.c :file_readable");
  87. #endif
  88.  if (!file_exists(filename))
  89.    {
  90. #ifdef TRACE
  91.     trace_return();
  92. #endif
  93.     return(TRUE);
  94.    }
  95.  if (access(filename,R_OK) == (-1))
  96.    {
  97. #ifdef TRACE
  98.     trace_return();
  99. #endif
  100.     return(FALSE);
  101.    }
  102. #ifdef TRACE
  103.     trace_return();
  104. #endif
  105.  return(TRUE);
  106. }
  107. /***********************************************************************/
  108. #ifdef PROTO
  109. short file_writable(CHARTYPE *filename)
  110. #else
  111. short file_writable(filename)
  112. CHARTYPE *filename;
  113. #endif
  114. /***********************************************************************/
  115. {
  116. /*--------------------------- local data ------------------------------*/
  117. /*--------------------------- processing ------------------------------*/
  118. #ifdef TRACE
  119.  trace_function("nonansi.c :file_writable");
  120. #endif
  121.  if (!file_exists(filename))
  122.    {
  123. #ifdef TRACE
  124.     trace_return();
  125. #endif
  126.     return(TRUE);
  127.    }
  128.  if (access(filename,W_OK) == (-1))
  129.    {
  130. #ifdef TRACE
  131.     trace_return();
  132. #endif
  133.     return(FALSE);
  134.    }
  135. #ifdef TRACE
  136.  trace_return();
  137. #endif
  138.  return(TRUE);
  139. }
  140. /***********************************************************************/
  141. #ifdef PROTO
  142. short file_exists(CHARTYPE *filename)
  143. #else
  144. short file_exists(filename)
  145. CHARTYPE *filename;
  146. #endif
  147. /***********************************************************************/
  148. {
  149. /*--------------------------- local data ------------------------------*/
  150. /*--------------------------- processing ------------------------------*/
  151. #ifdef TRACE
  152.  trace_function("nonansi.c :file_exists");
  153. #endif
  154.  if (access(filename,F_OK) == (-1))
  155.    {
  156. #ifdef TRACE
  157.     trace_return();
  158. #endif
  159.     return(FALSE);
  160.    }
  161. #ifdef TRACE
  162.  trace_return();
  163. #endif
  164.  return(TRUE);
  165. }
  166. /***********************************************************************/
  167. #ifdef PROTO
  168. short remove_file(CHARTYPE *filename)
  169. #else
  170. short remove_file(filename)
  171. CHARTYPE *filename;
  172. #endif
  173. /***********************************************************************/
  174. {
  175. /*--------------------------- local data ------------------------------*/
  176. /*--------------------------- processing ------------------------------*/
  177. #ifdef TRACE
  178.  trace_function("nonansi.c :remove_file");
  179. #endif
  180. if(filename == NULL)
  181.      return(RC_OK);
  182. #ifdef VMS
  183.  if (delete(filename) == (-1))
  184. #else
  185.  if (unlink(filename) == (-1))
  186. #endif
  187.    {
  188. #ifdef TRACE
  189.     trace_return();
  190. #endif
  191.     return(RC_ACCESS_DENIED);
  192.    }
  193. #ifdef TRACE
  194.  trace_return();
  195. #endif
  196.  return(RC_OK);
  197. }
  198. #if defined(DOS) || defined(OS2)
  199. /***********************************************************************/
  200. #ifdef PROTO
  201. short splitpath(CHARTYPE *filename)
  202. #else
  203. short splitpath(filename)
  204. CHARTYPE *filename;
  205. #endif
  206. /***********************************************************************/
  207. {
  208. /*-------------------------- external data ----------------------------*/
  209.  extern CHARTYPE curr_path[MAX_FILE_NAME+1];
  210.  extern CHARTYPE sp_fname[MAX_FILE_NAME+1];
  211.  extern CHARTYPE sp_path[MAX_FILE_NAME+1];
  212. /*--------------------------- local data ------------------------------*/
  213.  short len=0;
  214.  CHARTYPE work_filename[MAX_FILE_NAME+1] ;
  215.  CHARTYPE current_dir[MAX_FILE_NAME+1] ;
  216. #if defined(DOS)
  217.  short new_dos_disk=0,current_dos_disk=0;        /* 1 - A,2 - B... */
  218.  short temp_disk=0;
  219. #endif
  220. #ifdef OS2
  221.  ULONG logical_os2_drives=0L;
  222. #  ifdef __32BIT__
  223.  ULONG new_dos_disk=0L,current_dos_disk=0L,temp_disk=0L;
  224. #  else
  225.  USHORT new_dos_disk=0,current_dos_disk=0,temp_disk=0;
  226. #  endif
  227. #endif
  228. /*--------------------------- processing ------------------------------*/
  229. #ifdef TRACE
  230.  trace_function("nonansi.c :splitpath");
  231. #endif
  232.  strcpy(sp_path,"");
  233.  strcpy(sp_fname,"");
  234.  strcpy(work_filename,filename);
  235. /*---------------------------------------------------------------------*/
  236. /* If the supplied filename is empty, set the path = cwd and filename  */
  237. /* equal to blank.                                                     */
  238. /*---------------------------------------------------------------------*/
  239.  if (strcmp(filename,"") == 0)
  240.    {
  241. #if defined(EMX)
  242.     _getcwd2(sp_path,MAX_FILE_NAME);
  243. #else
  244.     getcwd(sp_path,MAX_FILE_NAME);
  245. #endif
  246.     strcpy(sp_fname,"");
  247.    }
  248. /*---------------------------------------------------------------------*/
  249. /* For DOS and OS/2, get current drive.                                */
  250. /*---------------------------------------------------------------------*/
  251. #ifdef DOS
  252. #  if defined(TC) || defined(GO32)
  253.  current_dos_disk = getdisk() + 1;
  254. #  else
  255.  _dos_getdrive(¤t_dos_disk);
  256. #  endif
  257. #endif
  258. #ifdef OS2
  259.  DosQueryCurrentDisk(¤t_dos_disk,&logical_os2_drives);
  260. #endif
  261.  
  262.  new_dos_disk = current_dos_disk;
  263. /*---------------------------------------------------------------------*/
  264. /* For DOS and OS/2, if a drive specified determine the drive number.  */
  265. /*---------------------------------------------------------------------*/
  266.  if (*(filename+1) == ':')/* we assume this means a drive secification */
  267.     new_dos_disk = (toupper(*(filename)) - 'A') + 1;
  268. /*---------------------------------------------------------------------*/
  269. /* For DOS and OS/2, change to the specified disk (if supplied and     */
  270. /* different). Validate the drive number.                              */
  271. /*---------------------------------------------------------------------*/
  272.  if (new_dos_disk != current_dos_disk)
  273.    {
  274. #ifdef DOS
  275. #  if defined(TC) || defined(GO32)
  276.     setdisk((short)(new_dos_disk-1));
  277.     temp_disk = getdisk()+1;
  278. #  else
  279.     _dos_setdrive(new_dos_disk,&temp_disk);
  280.     _dos_getdrive(&temp_disk);
  281. #  endif
  282. #endif
  283. #ifdef OS2
  284.     DosSetDefaultDisk(new_dos_disk);
  285.     DosQueryCurrentDisk(&temp_disk,&logical_os2_drives);
  286. #endif
  287.     if (temp_disk != new_dos_disk)  /* invalid drive */
  288.       {
  289. #ifdef TRACE
  290.        trace_return();
  291. #endif
  292.        return (RC_BAD_DRIVE);
  293.       }
  294.    }
  295. /*---------------------------------------------------------------------*/
  296. /* Save the current working directory on the specified drive, or the   */
  297. /* current drive if not specified.                                     */
  298. /*---------------------------------------------------------------------*/
  299. #if defined(EMX)
  300.  _getcwd2(current_dir,MAX_FILE_NAME);
  301. #else
  302.  getcwd(current_dir,MAX_FILE_NAME);
  303. #endif
  304. /*---------------------------------------------------------------------*/
  305. /* If the work_filename contains a drive specifier, special handling is*/
  306. /* needed.                                                             */
  307. /*---------------------------------------------------------------------*/
  308.  switch(strlen(filename))
  309.    {
  310.     case 1:
  311.          break;
  312. /*---------------------------------------------------------------------*/
  313. /* If the filename consists only of a drive specifier, copy the current*/
  314. /* directory for the now new drive into work_filename.                 */
  315. /*---------------------------------------------------------------------*/
  316.     case 2:
  317.          if (*(filename+1) == ':')
  318.             strcpy(work_filename,current_dir);
  319.          break;
  320.     default:
  321.          if (*(filename+1) == ':'
  322.          &&  *(filename+2) != ISLASH)
  323.            {
  324.             strcpy(work_filename,current_dir);
  325.             if (current_dir[strlen(current_dir)-1] != ISLASH)
  326.                strcat(work_filename,ISTR_SLASH);
  327.             strcat(work_filename,filename+2);
  328.            }
  329.          break;
  330.    }
  331. /*---------------------------------------------------------------------*/
  332. /* First determine if the supplied filename is a directory.            */
  333. /*---------------------------------------------------------------------*/
  334.  if (chdir(work_filename) == 0)  /* valid directory */
  335.    {
  336. #if defined(EMX)
  337.     _getcwd2(sp_path,MAX_FILE_NAME);
  338. #else
  339.     getcwd(sp_path,MAX_FILE_NAME);
  340. #endif
  341.     strcpy(sp_fname,"");
  342.    }
  343.  else          /* here if the file is not a directory */
  344.    {
  345.     len = strzreveq(work_filename,ISLASH);
  346.     switch(len)
  347.       {
  348.        case (-1):
  349. #if defined(EMX)
  350.             _getcwd2(sp_path,MAX_FILE_NAME);
  351. #else
  352.             getcwd(sp_path,MAX_FILE_NAME);
  353. #endif
  354.             strcpy(sp_fname,work_filename);
  355.             break;
  356.        case 0:
  357.             strcpy(sp_path,work_filename);
  358.             sp_path[1] = '\0';
  359.             strcpy(sp_fname,work_filename+1+len);
  360.             break;
  361.       default:
  362.             strcpy(sp_path,work_filename);
  363.             sp_path[len] = '\0';
  364.             strcpy(sp_fname,work_filename+1+len);
  365.             break;
  366.      }
  367.    }
  368.  if (strlen(sp_path) == 2
  369.  && sp_path[1] == ':')
  370.     strcat(sp_path,ISTR_SLASH);
  371. /*---------------------------------------------------------------------*/
  372. /* Change directory to the supplied path, if possible and store the    */
  373. /* expanded path.                                                      */
  374. /* If an error, restore the current path.                              */
  375. /*---------------------------------------------------------------------*/
  376.  if (chdir(sp_path) != 0)
  377.    {
  378.     if (new_dos_disk != current_dos_disk)
  379.       {
  380.        chdir(current_dir);
  381. #ifdef DOS
  382. #  if defined(TC) || defined(GO32)
  383.        setdisk((short)(current_dos_disk-1));
  384. #  else
  385.        _dos_setdrive(current_dos_disk,&temp_disk);
  386. #  endif
  387. #endif
  388. #ifdef OS2
  389.        DosSetDefaultDisk(new_dos_disk);
  390. #endif
  391.       }
  392.     chdir(curr_path);
  393. #ifdef TRACE
  394.     trace_return();
  395. #endif
  396.     return(RC_FILE_NOT_FOUND);
  397.    }
  398. /*---------------------------------------------------------------------*/
  399. /* We are now in a valid directory, get the fully qualified directory  */
  400. /* name.                                                               */
  401. /*---------------------------------------------------------------------*/
  402. #if defined(EMX)
  403.  _getcwd2(sp_path,MAX_FILE_NAME);
  404. #else
  405.  getcwd(sp_path,MAX_FILE_NAME);
  406. #endif
  407. /*---------------------------------------------------------------------*/
  408. /* For DOS or OS/2, change back to the current directory of the now    */
  409. /* current disk and then change back to the original disk.             */
  410. /*---------------------------------------------------------------------*/
  411.  if (new_dos_disk != current_dos_disk)
  412.    {
  413.     if (chdir(current_dir) != 0)
  414.       {
  415. #ifdef TRACE
  416.        trace_return();
  417. #endif
  418.        return(RC_FILE_NOT_FOUND);
  419.       }
  420. #ifdef DOS
  421. #  if defined(TC) || defined(GO32)
  422.     setdisk((short)(current_dos_disk-1));
  423. #  else
  424.     _dos_setdrive(current_dos_disk,&temp_disk);
  425. #  endif
  426. #endif
  427. #ifdef OS2
  428.     DosSetDefaultDisk(current_dos_disk);
  429. #endif
  430.    }
  431.  
  432.  chdir(curr_path);
  433. /*---------------------------------------------------------------------*/
  434. /* Append the OS directory character to the path if it doesn't already */
  435. /* end in the character.                                               */
  436. /*---------------------------------------------------------------------*/
  437. #ifndef VMS
  438.  len = strlen(sp_path);
  439.  if (len > 0)
  440.     if (sp_path[len-1] != ISLASH)
  441.        strcat(sp_path,(CHARTYPE *)ISTR_SLASH);
  442. #endif
  443. #ifdef TRACE
  444.  trace_return();
  445. #endif
  446.  return(RC_OK);
  447. }
  448. #else
  449. /***********************************************************************/
  450. #ifdef PROTO
  451. short splitpath(CHARTYPE *filename)
  452. #else
  453. short splitpath(filename)
  454. CHARTYPE *filename;
  455. #endif
  456. /***********************************************************************/
  457. {
  458. /*-------------------------- external data ----------------------------*/
  459.  extern CHARTYPE curr_path[MAX_FILE_NAME+1];
  460.  extern CHARTYPE sp_fname[MAX_FILE_NAME+1];
  461.  extern CHARTYPE sp_path[MAX_FILE_NAME+1];
  462.  extern struct stat stat_buf;
  463. /*--------------------------- local data ------------------------------*/
  464.  short len=0;
  465.  CHARTYPE work_filename[MAX_FILE_NAME+1] ;
  466. /*--------------------------- processing ------------------------------*/
  467. #ifdef TRACE
  468.  trace_function("nonansi.c :splitpath");
  469. #endif
  470.  strcpy(sp_path,"");
  471.  strcpy(sp_fname,"");
  472.  strcpy(work_filename,filename);
  473. /*---------------------------------------------------------------------*/
  474. /* If the supplied filename is empty, set the path = cwd and filename  */
  475. /* equal to blank.                                                     */
  476. /*---------------------------------------------------------------------*/
  477.  if (strcmp(filename,"") == 0)
  478.    {
  479.     getcwd(sp_path,MAX_FILE_NAME);
  480.     strcpy(sp_fname,"");
  481.    }
  482. /*---------------------------------------------------------------------*/
  483. /* Check if the first character is tilde; translate HOME env variable  */
  484. /* if there is one. Obviously only applicable to UNIX.                 */
  485. /*---------------------------------------------------------------------*/
  486.  if (*(work_filename) == '~')
  487.    {
  488.     if (*(work_filename+1) == ISLASH)
  489.       {
  490.        strcpy(work_filename,(CHARTYPE *)getenv("HOME"));
  491.        strcat(work_filename,(filename+1));
  492.       }
  493.     else
  494.       {
  495.        struct passwd *pwd;
  496.  
  497.        strcpy(sp_path,filename+1);
  498.        if ((len = strzeq(sp_path,ISLASH)) != (-1))
  499.           sp_path[len] = '\0';
  500.        if ((pwd = getpwnam(sp_path)) == NULL)
  501.           return(RC_BAD_FILEID);
  502.        strcpy(work_filename,pwd->pw_dir);
  503.        if (len != (-1))
  504.           strcat(work_filename,(filename+1+len));
  505.       }
  506.    }
  507. /*---------------------------------------------------------------------*/
  508. /* First determine if the supplied filename is a directory.            */
  509. /*---------------------------------------------------------------------*/
  510.  if ((stat(work_filename,&stat_buf) == 0)
  511.  &&  (stat_buf.st_mode & S_IFMT) == S_IFDIR)
  512.    {
  513.     strcpy(sp_path,work_filename);
  514.     strcpy(sp_fname,"");
  515.    }
  516.  else          /* here if the file doesn't exist or is not a directory */
  517.    {
  518.     len = strzreveq(work_filename,ISLASH);
  519.     switch(len)
  520.       {
  521.        case (-1):
  522.             getcwd(sp_path,MAX_FILE_NAME);
  523.             strcpy(sp_fname,work_filename);
  524.             break;
  525.        case 0:
  526.             strcpy(sp_path,work_filename);
  527.             sp_path[1] = '\0';
  528.             strcpy(sp_fname,work_filename+1+len);
  529.             break;
  530.       default:
  531.             strcpy(sp_path,work_filename);
  532.             sp_path[len] = '\0';
  533.             strcpy(sp_fname,work_filename+1+len);
  534.             break;
  535.      }
  536.    }
  537. /*---------------------------------------------------------------------*/
  538. /* Change directory to the supplied path, if possible and store the    */
  539. /* expanded path.                                                      */
  540. /* If an error, restore the current path.                              */
  541. /*---------------------------------------------------------------------*/
  542.  if (chdir(sp_path) != 0)
  543.    {
  544.     chdir(curr_path);
  545. #ifdef TRACE
  546.     trace_return();
  547. #endif
  548.     return(RC_FILE_NOT_FOUND);
  549.    }
  550.  getcwd(sp_path,MAX_FILE_NAME);
  551.  chdir(curr_path);
  552. /*---------------------------------------------------------------------*/
  553. /* Append the OS directory character to the path if it doesn't already */
  554. /* end in the character.                                               */
  555. /*---------------------------------------------------------------------*/
  556. #ifndef VMS
  557.  len = strlen(sp_path);
  558.  if (len > 0)
  559.     if (sp_path[len-1] != ISLASH)
  560.        strcat(sp_path,(CHARTYPE *)ISTR_SLASH);
  561. #endif
  562. #ifdef TRACE
  563.  trace_return();
  564. #endif
  565.  return(RC_OK);
  566. }
  567. #endif
  568.  
  569. #if defined(NO_RENAME)
  570. /***********************************************************************/
  571. #ifdef PROTO
  572. short rename(CHARTYPE *path1,CHARTYPE *path2)
  573. #else
  574. short rename(path1,path2)
  575. CHARTYPE *path1;
  576. CHARTYPE *path2;
  577. #endif
  578. /***********************************************************************/
  579. /* Function  : Emulate missing rename() function missing from SystemV  */
  580. /* Parameters: path1    - old filename                                 */
  581. /*             path2    - new_filename                                 */
  582. /* Return    : 0 on success, -1 on error                               */
  583. /***********************************************************************/
  584. {
  585. #ifdef TRACE
  586.  trace_function("nonansi.c :rename");
  587. #endif
  588.   if (link(path1,path2) != 0)
  589.     {
  590. #ifdef TRACE
  591.      trace_return();
  592. #endif
  593.      return(-1);
  594.     }
  595.   if (unlink(path1) != 0)
  596.     {
  597. #ifdef TRACE
  598.      trace_return();
  599. #endif
  600.      return(-1);
  601.     }
  602. #ifdef TRACE
  603.  trace_return();
  604. #endif
  605.  return(0);
  606. }
  607. #endif
  608.  
  609. #ifdef OS2
  610.  
  611. #  ifdef __32BIT__
  612. #  define FSQBUFFERSIZE 64
  613.  
  614. /***********************************************************************/
  615. bool LongFileNames(CHARTYPE *path)
  616. /***********************************************************************/
  617. /* Function  : Determine if file system allows long file names. (HPFS) */
  618. /*             This is the 32-bit version.                             */
  619. /* Parameters: path     - directory path                               */
  620. /* Return    : 1 if file system is HPFS                                */
  621. /***********************************************************************/
  622. {
  623. /*--------------------------- local data ------------------------------*/
  624.         ULONG nDrive=0L;
  625.         ULONG lMap=0L;
  626.         char buffer[FSQBUFFERSIZE];
  627.         FSQBUFFER2 *bData = (FSQBUFFER2 *) buffer;
  628.         char bName[3];
  629.         ULONG bDataLen=0L;
  630. /*--------------------------- processing ------------------------------*/
  631. #ifdef TRACE
  632.  trace_function("file.c:    LongFileNames");
  633. #endif
  634.  if ((strlen (path) > 0) && path [1] == ':')
  635.     bName[0] = path[0];
  636.  else
  637.    {
  638.     DosQueryCurrentDisk(&nDrive, &lMap);
  639.     bName[0] = (char) (nDrive + 'A' - 1);
  640.    }
  641.  bName[1] = ':';
  642.  bName[2] = 0;
  643.  bDataLen = FSQBUFFERSIZE;
  644.  DosQueryFSAttach(bName, 0, FSAIL_QUERYNAME, bData, &bDataLen);
  645.  return(strcmp(bData->szFSDName + bData->cbName, "HPFS") == 0);
  646. }
  647. #  else
  648.  
  649. /***********************************************************************/
  650. bool LongFileNames(CHARTYPE *path)
  651. /***********************************************************************/
  652. /* Function  : Determine if file system allows long filenames. (HPFS)  */
  653. /*             This is the 16-bit version.                             */
  654. /* Parameters: path     - directory path                               */
  655. /* Return    : 1 if file system is HPFS                                */
  656. /***********************************************************************/
  657. {
  658. typedef struct _FSNAME {
  659.         USHORT cbName;
  660.         UCHAR  szName[1];
  661. } FSNAME;
  662. typedef struct _FSQINFO {
  663.         USHORT iType;
  664.         FSNAME Name;
  665.         UCHAR  rgFSAData[59];
  666. } FSQINFO;
  667. typedef FSQINFO FAR *PFSQINFO;
  668. /*--------------------------- local data ------------------------------*/
  669.  USHORT nDrive=0,cbData=0;
  670.  ULONG lMap=0L;
  671.  FSQINFO bData;
  672.  BYTE bName[3];
  673.  FSNAME *pFSName=NULL;
  674. /*--------------------------- processing ------------------------------*/
  675. #ifdef TRACE
  676.  trace_function("file.c:    LongFileNames");
  677. #endif
  678.  if ((strlen(path) > 0) && path[1] == ':')
  679.     bName[0] = path[0];
  680.  else
  681.    {
  682.     DosQueryCurrentDisk(&nDrive, &lMap);
  683.     bName[0] = (char)(nDrive + '@');
  684.    }
  685.  bName[1] = ':';
  686.  bName[2] = 0;
  687.  cbData = sizeof(bData);
  688.  DosQFSAttach((PSZ)bName,0,1,(PBYTE)&bData,&cbData,0L);
  689.  pFSName = &bData.Name;
  690.  (CHARTYPE *)pFSName += pFSName->cbName + sizeof(pFSName->cbName)+1;
  691.  return(strcmp((CHARTYPE *)&(pFSName->szName[0]),"HPFS") == 0);
  692. }
  693. #  endif
  694. #endif
  695.  
  696. #ifdef PRE_111_GO32
  697. /***********************************************************************/
  698. #ifdef PROTO
  699. short getdisk(void)
  700. #else
  701. short getdisk()
  702. #endif
  703. /***********************************************************************/
  704. /* Function  : Determine the drive letter for the current disk.        */
  705. /* Parameters: nil                                                     */
  706. /* Return    : 0 for drive A:, 1 for drive B:, etc...                  */
  707. /***********************************************************************/
  708. {
  709. /*--------------------------- local data ------------------------------*/
  710. /*--------------------------- processing ------------------------------*/
  711.  regs.h.ah = 0x19;
  712.  int86(0x21, ®s, ®s);
  713.  return ((short) regs.h.al);
  714. }
  715. /***********************************************************************/
  716. #ifdef PROTO
  717. short setdisk(short drive)
  718. #else
  719. short setdisk(drive)
  720. short drive;
  721. #endif
  722. /***********************************************************************/
  723. /* Function  : Change the current drive to that specified.             */
  724. /* Parameters: 0 for drive A:, 2 for drive B:, etc...                  */
  725. /* Return    : number of drives present                                */
  726. /***********************************************************************/
  727. {
  728. /*--------------------------- local data ------------------------------*/
  729. /*--------------------------- processing ------------------------------*/
  730.  regs.h.ah = 0x0e;
  731.  regs.h.dl = (char)drive;
  732.  int86(0x21, ®s, ®s);
  733.  return ((short) regs.h.al);
  734. }
  735. #endif
  736.